using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Enemy_GetHurt : MonoBehaviour
{
    public float Hpmax;
    public float Hpcur;
    public float Hpmax_initial;
    public GameObject HurtNum;

    public float dianran_time;
    public int dianran_num;

    public float jiansu_time;
    public int jiansu_num;
    public bool jiansu_ison;
    public Player_Control player;
    public Player_Buff Player_Buff;
    // Start is called before the first frame update
    void Start()
    {
        player = GameObject.Find("Player").GetComponent<Player_Control>();
        Player_Buff = GameObject.Find("Player").GetComponent<Player_Buff>();
        dianran_time = 0.3f;
        jiansu_time = 0.3f;
        jiansu_ison = false;
        Hpcur = Hpmax;
    }

    // Update is called once per frame
    void Update()
    {
        HongLianHuo();
        BingFengPo();
    }

    public void GetHurt(float atk)
    {
        Hpcur -= atk;
        GameObject go = Instantiate(HurtNum);
        int num1 = Mathf.FloorToInt(atk);
        go.GetComponent<TextMesh>().text = "-"+ num1.ToString();
        go.transform.position = transform.position + transform.up * Random.Range(1.5f,3f)+transform.right*Random.Range(-1f,1.5f); 
        Destroy(go, 0.4f);
    }


    public void HongLianHuo()
    {
        if(dianran_num>0)
        {
            dianran_time -= Time.deltaTime;
            if(dianran_time<=0)
            {
                GetHurt(player.curAtk_player*0.25f*Player_Buff.HongLianHuo_Level);
                dianran_time = 0.3f;
                dianran_num -= 1;
            }
        }
    }

    public void BingFengPo()
    {
        if(jiansu_num>0)
        {
            jiansu_ison = true;
            jiansu_time -= Time.deltaTime;
            if(jiansu_time<=0)
            {
                GetHurt(player.curAtk_player * 0.15f * Player_Buff.BingFengPo_Level);
                jiansu_time = 0.3f;
                jiansu_num -= 1;
            }
        }else if(jiansu_num<=0)
        {
            jiansu_ison = false;
        }

    }
}
